/**
 * 项目详情--js
 * @author cl
 * @date 2019年4月1日
 */
var project_detail = {
	_UUID:null,
	_OBJ:null,
	init : function() {
		var obj = GetRequest();
		project_detail._UUID = obj.uuid;
		project_detail.findById(project_detail._UUID);
	},
	/**
	 * 查询项目详情
	 */
	findById:function(uuid){
		$.ajax({
			url : "/crm/project/findByUuid", 
			dataType : "json", 
			async : true,
			data : {
				uuid:uuid
			},
			type : "post",
			success : function(data) {
				project_detail._OBJ=data;
				$("#proName").val(data.proName);
				$("#liablePerson").val(data.liableUserName);
				$("#teamMembers").val(data.teamMembersNames);
				$("#beginTime").val(data.beginTime);
				$("#createTime").val(data.createTime);
				$("#nextStepTime").val(data.nextStepTime);
				$("#powerUsers").val(data.powerUserName);
				$("#proRemarks").val(data.proRemarks);
				project_detail.findAccessory();
				project_detail.findProgress();
			},
			error : function() {
				layer.msg("系统错误！", {icon: 2,closeBtn: 0 });;
			}
		});
	},
	/**
	 * 检索项目方案和进度获取条件
	 */
	getPPParam:function() {
		var obj = {};
		obj.pageIndex = 1;
		obj.pageSize = 1000;
		var searchWord = {};
		searchWord.dataUuid = project_detail._OBJ.uuid;//  查询字段
		obj.conditions = JSON.stringify(searchWord);
		return obj;
	},
	/**
	 * 查询项目进度列表
	 * @param dataUuid
	 */
	findProgress:function(){
		$.ajax({
			url : "/crm/progress/loadProgressByDataUuid", 
			dataType : "json", 
			async : true,
			data : {"uuid":project_detail._OBJ.uuid},
			type : "post",
			success : function(data) {
				if(data.length>0){
					var html ='<tr class="first_tr"><th style="width:5%;">序号</th><th style="width:20%;">进度标题</th><th style="max-width:30%;">进度描述</th><th style="width:10%;">下一节点时间</th><th style="width:10%;">创建时间</th><th style="width:10%;">附件</th><th style="width:15%;">操作</th></tr>';
					var num1 = 0;
					var num2 = 0;
					$(data).each(function(key,val){
						if(val.puuid=="0"){
							if(key!=0){
								html+='<tr></tr>';
							}
							num1++;
							html+='<tr><td>第'+num1+'进度</td></tr>';
							if(key%2==0){
								html+='<tr>';
							}else{
								html+='<tr class="tr_shade">';
							}
							num2=0;
							html+='<td>'+num1+'</td>';
						}else{
							if(key%2==0){
								html+='<tr>';
							}else{
								html+='<tr class="tr_shade">';
							}
							num2++;
							html+='<td>'+num1+'.'+num2+'</td>';
						}
						html+='<td>'+val.proTitle+'</td>';
						html+='<td>'+val.proDescribe+'</td>';
						html+='<td>'+val.nextStepTime+'</td>';
						html+='<td>'+val.createTime+'</td>';
						if(isBlank(val.proFilePath)){
							html+='<td>--</td>';
							html+='<td>--</td>';
						}else{
							html+='<td>'+val.proFilePath.substring(val.proFilePath.lastIndexOf("/") + 1)+'</td>';
							html+='<td><a onclick="preview(\''+val.proFilePath+'\',1)">预览</a><a onclick="downloadServer(\''+val.proFilePath+'\',1)">下载</a></td>';
						}
						html+='</tr>';
					});
					$("#progressTable").html(html);
				}
			},
			error : function() {
				layer.msg("系统错误！", {icon: 2,closeBtn: 0 });;
			}
		});
	},
	/**
	 * 查询项目方案列表
	 * @param dataUuid
	 */
	findAccessory:function(){
		$.ajax({
			url : "/crm/accessory/findBySpec", 
			dataType : "json", 
			async : true,
			data : project_detail.getPPParam(),
			type : "post",
			success : function(data) {
				if(data.total>0){
					var html='<tr class="first_tr"><th style="width:20%;">方案名称</th><th style="width:45%;">方案描述</th><th style="width:15%;">上传时间</th><th style="width:10%;">附件</th><th style="width:10%;"></th></tr>';
					$(data.rows).each(function(key,val){
						if(key%2==0){
							html+='<tr>';
						}else{
							html+='<tr class="tr_shade">';
						}
						html+='<td>'+val.accTitle+'</td>';
						html+='<td>'+val.planDescribe+'</td>';
						html+='<td>'+val.createTime+'</td>';
						if(isBlank(val.accFilePath)){
							html+='<td>--</td>';
							html+='<td>--</td>';
						}else{
							html+='<td>'+val.accFilePath.substring(val.accFilePath.lastIndexOf("/") + 1)+'</td>';
							html+='<td><a onclick="preview(\''+val.accFilePath+'\',1)">预览</a><a onclick="downloadServer(\''+val.accFilePath+'\',1)">下载</a></td>';
						}
						html+='</tr>';
					});
					$("#planTable").html(html);
				}
			},
			error : function() {
				layer.msg("系统错误！", {icon: 2,closeBtn: 0 });;
			}
		});
	}
}